package com.shuzijun.leetcode.editor.cn;

import java.util.ArrayList;

public class BaShuZiFanYiChengZiFuChuanLcof{
    public static void main(String[] args) {
         Solution solution = new BaShuZiFanYiChengZiFuChuanLcof().new Solution();
    }
    //leetcode submit region begin(Prohibit modification and deletion)
class Solution {
    public int translateNum(int num) {
        if (num <= 9) return 1;
        ArrayList<Integer> dig = new ArrayList<>();
        while (num != 0){
            dig.add(num % 10);
            num /= 10;
        }

        int n = dig.size();
        int[] dig2 = new int[n];
        for (int i = 0; i < n; i++) {
            dig2[i] = dig.get(n - i - 1);
        }
        int[] dp = new int[n + 1];
        dp[0] = 1;

        for (int i = 1; i <= n; i++) {
            dp[i] = dp[i-1];
            if (i-2 >= 0 && isValids(dig2[i-2],dig2[i-1])){
                dp[i] += dp[i-2];
            }
        }
        return dp[n];
    }

        private boolean isValids(int a, int b) {
        if (a ==1)return true;
        if (a == 2 && b>=0 && b <= 5) return true;
        return false;
        }
    }
//leetcode submit region end(Prohibit modification and deletion)

}